﻿<!--
	========================================================================
	 NQ Software Development Kit Component
	
	 Homepage: http://www.awzhome.de/
	========================================================================
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Software Development Kit Component.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	========================================================================
-->

<UserControl x:Class="AWZhome.NQsdk.Visual.SystemBrowserView"
	 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	 xmlns:nqcs="clr-namespace:AWZhome.NQ.CommonServices;assembly=NQCommServ.Interface"
	 xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
	 xmlns:nqsdk="clr-namespace:AWZhome.NQsdk.Services"
	 xmlns:nqsdkhelpers="clr-namespace:AWZhome.NQsdk.Helpers"
	 xmlns:nqsdkvisual="clr-namespace:AWZhome.NQsdk.Visual"
	 Background="{x:Static SystemColors.ControlBrush}">

	<UserControl.Resources>
		<!-- DataTemplate for component ListView items -->
		<CollectionViewSource x:Key="ComponentSortedDataSource">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription PropertyName="IsRegularComponent" Direction="Ascending" />
				<scm:SortDescription PropertyName="Name" Direction="Ascending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<DataTemplate x:Key="ComponentDataTemplate">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Height="16" Width="16"
							  Style="{DynamicResource ComponentItemImageStyle}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=Name}" />
			</Grid>
		</DataTemplate>

		<Style x:Key="ComponentItemImageStyle" TargetType="{x:Type Image}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding IsRegularComponent}" Value="True">
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Component.png, Type=ImageSource}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<!-- DataTemplate for AttachList ListView items -->
		<CollectionViewSource x:Key="AttachListSortedDataSource">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription Direction="Ascending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<DataTemplate x:Key="AttachListDataTemplate">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image Grid.Column="0" Height="16" Width="16"
						 Source="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/AttachList.png, Type=ImageSource}" />
				<TextBlock Grid.Column="1" Text="{Binding}" />
			</Grid>
		</DataTemplate>

		<!-- DataTemplate for interface ListView items -->
		<CollectionViewSource x:Key="InterfaceSortedDataSource">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription PropertyName="FullName" Direction="Ascending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<DataTemplate x:Key="InterfaceDataTemplate">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image
					Grid.Column="0" Height="16" Width="16"
					Source="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Interface.png, Type=ImageSource}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=FullName}" />
			</Grid>
		</DataTemplate>

		<!-- HierarchicalDataTemplate for service TreeView items -->
		<CollectionViewSource x:Key="ServiceSortedDataSource">
			<CollectionViewSource.SortDescriptions>
				<scm:SortDescription PropertyName="ServiceInfo.ServiceInterface.Name" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<HierarchicalDataTemplate
			DataType="{x:Type nqsdkhelpers:ServiceEntry}"
			ItemsSource="{Binding SubEntries}">
			
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="20" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image
					Grid.Column="0" Height="16" Width="16"
					Style="{DynamicResource ItemImageStyle}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=ServiceInfo.ServiceInterface.Name}" />
			</Grid>
		</HierarchicalDataTemplate>

		<Style x:Key="ItemImageStyle" TargetType="{x:Type Image}">
			<Style.Triggers>
				<!-- Non substituted multi-instance service -->
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding IsSubstituted}" Value="False" />
						<Condition Binding="{Binding IsSingleInstance}" Value="False" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Service.png, Type=ImageSource}" />
				</MultiDataTrigger>
				<!-- Substituted multi-instance service -->
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding IsSubstituted}" Value="True" />
						<Condition Binding="{Binding IsSingleInstance}" Value="False" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/ServiceSubstituted.png, Type=ImageSource}" />
				</MultiDataTrigger>
				<!-- Non-substituted single-instance service -->
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding IsSubstituted}" Value="False" />
						<Condition Binding="{Binding IsSingleInstance}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/ServiceSingle.png, Type=ImageSource}" />
				</MultiDataTrigger>
				<!-- Substituted single-instance service -->
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding IsSubstituted}" Value="True" />
						<Condition Binding="{Binding IsSingleInstance}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/ServiceSingleSubstituted.png, Type=ImageSource}" />
				</MultiDataTrigger>
			</Style.Triggers>
		</Style>
	</UserControl.Resources>

	<Grid Name="ListGrid">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="200" />
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>

		<!-- List for components, TreeView for Services -->
		<Grid Name="InnerListGrid" Grid.Column="0" Margin="0,0,5,0" >
			<Grid.RowDefinitions>
				<RowDefinition Height="200" />
				<RowDefinition Height="*" />
			</Grid.RowDefinitions>
			<nqcs:BarHostControl Name="NQsdkSystemBrowserBar" Grid.Row="0">
				<ListBox
					Margin="0,0,0,0"
					ItemTemplate="{StaticResource ComponentDataTemplate}"
					ItemsSource="{Binding Source={StaticResource ComponentSortedDataSource}}" />
				<ListBox
					Margin="0,0,0,0"
					ItemTemplate="{StaticResource AttachListDataTemplate}"
					ItemsSource="{Binding Source={StaticResource AttachListSortedDataSource}}" />
				<ListBox
					Margin="0,0,0,0"
					ItemTemplate="{StaticResource InterfaceDataTemplate}"
					ItemsSource="{Binding Source={StaticResource InterfaceSortedDataSource}}" />
			</nqcs:BarHostControl>
			<GridSplitter Name="HorizGridSplitter" Height="5" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
			<TreeView
				Grid.Row="1" Name="ServiceTreeView"
				ItemsSource="{Binding Source={StaticResource ServiceSortedDataSource}}" />
		</Grid>

		<GridSplitter Name="VertGridSplitter" Width="5" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Stretch" />

		<!-- On the right side: Component and service information area -->
		<Grid Grid.Column="1">
			<nqsdkvisual:ComponentServiceInformation x:Name="ComponentServiceInfo" />
		</Grid>
	</Grid>
</UserControl>
